# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: dorphell <dorphell@gmx.net>

pkgbase=unrar
pkgname=(unrar libunrar)
pkgver=6.2.7
pkgrel=1
epoch=1
arch=(x86_64)
url='https://www.rarlab.com/rar_add.htm'
license=(custom)
source=(https://www.rarlab.com/rar/unrarsrc-$pkgver.tar.gz)
sha256sums=('f071169f3f20a564f9cf1c8976c64e72de3b9cdbcccaa43a0c66472eb737aa01')

prepare() {
  sed -e '/CXXFLAGS=/d' -e '/LDFLAGS=/d' -i unrar/makefile # Use system build flags
}

build() {
  cp -a unrar libunrar
  export LDFLAGS+=' -pthread'
  make -C libunrar lib
  make -C unrar -j1
}

package_unrar() {
  pkgdesc='The RAR uncompression program'
  depends=(gcc-libs)
  cd unrar
  install -Dm755 unrar -t "$pkgdir"/usr/bin/
  # install license
  install -Dm644 license.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_libunrar() {
  pkgdesc='Library and header file for applications that use libunrar'
  depends=(gcc-libs)
  cd libunrar
  install -Dm755 libunrar.so -t "$pkgdir"/usr/lib/
  install -Dm644 dll.hpp -t "$pkgdir"/usr/include/unrar/
  # install license
  install -Dm644 license.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
